/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CcrXml.java
 *
 * Created on Nov 24, 2010, 2:25:34 PM
 */
package com.vn.ccrreader;

import com.google.code.ccr4j.ContinuityOfCareRecordDocument;
import java.awt.FlowLayout;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JTabbedPane;
import org.apache.xmlbeans.XmlException;

/**
 *
 * @author jyothis
 */
public class CcrXml extends javax.swing.JPanel {

    private static int count = 0;
    private final JTabbedPane jTabbedPane;
    private ContinuityOfCareRecordDocument ccrDoc;

    /** Creates new form CcrXml */
    public CcrXml(JTabbedPane jTabbedPane) {
        super(new FlowLayout(FlowLayout.LEFT, 0, 0));
        initComponents();
        this.jTabbedPane = jTabbedPane;
        //javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(this);
        //this.setLayout(jPanelLayout);
       // jPanelLayout.setHorizontalGroup(
        //        jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 392, Short.MAX_VALUE));
        //jPanelLayout.setVerticalGroup(
        //        jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 207, Short.MAX_VALUE));
    }

    public void addNewPanel() {

        final JFileChooser fc = new JFileChooser();
        //In response to a button click:
        int returnVal = fc.showOpenDialog(jTabbedPane);
        File newFile = fc.getSelectedFile();
        try {
            ccrDoc = ContinuityOfCareRecordDocument.Factory.parse(newFile);
            //System.out.println("XML IS :\n" + ccrDoc.getContinuityOfCareRecord().toString());
        } catch (XmlException ex) {
            Logger.getLogger(CcrXml.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CcrXml.class.getName()).log(Level.SEVERE, null, ex);
        }
        count++;
        jTabbedPane.addTab( ccrDoc.getContinuityOfCareRecord().getCCRDocumentObjectID(), this);
        //this.jCcrText.setText(ccrDoc.xmlText());
        jScrollPane1.repaint();
        add(jCcrText);
        repaint();
        jTabbedPane.setSelectedIndex(jTabbedPane.getTabCount() - 1);

    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jCcrText = new javax.swing.JTextArea();

        jCcrText.setColumns(20);
        jCcrText.setRows(5);
        jCcrText.setText("Hello...");
        jScrollPane1.setViewportView(jCcrText);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea jCcrText;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
